const MongoClient = require("mongodb").MongoClient;

const url = "mongodb://localhost:27017";

const dbName = "project";

const client = new MongoClient(url);

//数据库连接的方法封装
const connect = async (callback) => {
  await client.connect();
  console.log("Connected successfully to server");
  const db = client.db(dbName);
  callback && callback(db);
//   client.close();
};

module.exports = {
  connect,
};
